package com.tql.pandian.controller;

import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.model.LoginUser;
import com.tql.pandian.entity.dto.CreatePanDianDataDTO;
import com.tql.pandian.entity.dto.PanDianDataDTO;
import com.tql.pandian.entity.dto.PianDianDataListDTO;
import com.tql.pandian.entity.dto.UpdatePanDianDataData;
import com.tql.pandian.service.ICommonService;
import com.tql.pandian.service.IPandianDataService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 盘点数据详情表 tql_pandian_data
 */
@RestController
@RequestMapping("/pandianData")
@ApiOperation("盘点菜单")
public class PandianDataController extends BaseController {

    @Autowired
    private IPandianDataService pandianDataService;

    @Autowired
    private ICommonService commonService;

    @ApiOperation("盘点菜单-盘点单列表")
    @Log(title = "盘点菜单-盘点单列表", businessType = BusinessType.OTHER)
    @PostMapping("/getPanDianData")
    public AjaxResult getPanDianData(@RequestBody PanDianDataDTO panDianDataDTO){
        LoginUser loginUser= SecurityUtils.getLoginUser();
        Long userId=loginUser.getUserid();
        boolean flag= SecurityUtils.isAdmin(userId);
        if (!flag){
            /*String deptCode=commonService.findShopDeptCodeByUserId(userId);
            if(StringUtils.isEmpty(deptCode))
                return error("建议重新登录或检查账号是否正确配置门店");*/
            String deptCode = SecurityUtils.getLoginUser().getSysUser().getDeptCode();
            panDianDataDTO.setDeptCode(deptCode);
        }
        return success(pandianDataService.getPanDianData(panDianDataDTO));
    }

    @ApiOperation("盘点菜单-创建盘点")
    @Log(title = "盘点菜单-创建盘点", businessType = BusinessType.INSERT)
    @PostMapping("/createPanDianData")
    public AjaxResult createPanDianData(@RequestBody PianDianDataListDTO createPanDianDataDTO){
        return success(pandianDataService.createPanDianData(createPanDianDataDTO));
    }

    @ApiOperation("盘点菜单-获取盘点编辑数据")
    @Log(title = "盘点菜单-获取盘点编辑数据", businessType = BusinessType.OTHER)
    @PostMapping("/getPanDianDataById")
    public AjaxResult getPanDianDataById(@RequestBody UpdatePanDianDataData dto){

        return success(pandianDataService.getPanDianDataById(dto));
    }


    @ApiOperation("获取某库位某班组下的物料信息")
    @Log(title = "获取某库位某班组下的物料信息", businessType = BusinessType.OTHER)
    @PostMapping("/getStapInfoByStapCode")
    public AjaxResult getStapInfoByStapCode(@RequestBody UpdatePanDianDataData dto){

        return success(pandianDataService.getStapInfoByStapCode(dto));
    }





    @ApiOperation("盘点菜单-更新盘点列表")
    @Log(title = "盘点菜单-更新盘点列表", businessType = BusinessType.UPDATE)
    @PostMapping("/updatePanDianData")
    public AjaxResult updatePanDianData(@RequestBody CreatePanDianDataDTO createPanDianDataDTO){
        return success(pandianDataService.updatePanDianData(createPanDianDataDTO));
    }
}
